package com.work.controller;

import com.alibaba.fastjson.JSON;
import com.work.pojo.GoodsType;
import com.work.service.GoodsTypeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.servlet.ModelAndView;

import java.util.List;

/**
 * 商品类型控制器
 *
 * @author gy
 * &#064;date 2022/09/29
 * @version 1.0.0
 * @since 1.0.0
 */
@RestController
@RequestMapping("/goodstypes")
public class GoodsTypeController {
	@Autowired
	private GoodsTypeService typeService;
	
	@GetMapping("listGoodsType")
	public ModelAndView goodsTypeList(ModelAndView modelAndView){
		List<GoodsType> list  = typeService.GoodsTypelist();
		modelAndView.addObject( "goodsTypeList", list);
		modelAndView.setViewName( "forward:/admin/showGoodsType.jsp" );
		return modelAndView;
	}


	@GetMapping("toaddGoodsType")
	public ModelAndView toaddGoodsType(ModelAndView modelAndView){
		List<GoodsType> list  = typeService.GoodsTypelist();
		modelAndView.addObject( "goodsTypeList", list);
		modelAndView.setViewName( "forward:/admin/addGoodsType.jsp" );
		return modelAndView;
	}

	@PostMapping("addGoodsType")
	public ModelAndView addGoodsType(String typename,String goodsParent){

			int parent = Integer.parseInt( goodsParent );

		typeService.addGoodsType(parent,typename);

		return null;
	}
	@GetMapping("goodstypelist")
	public List goodstypelist(ModelAndView modelAndView){
		List<GoodsType> list  = typeService.goodstypelist();
		return list;
	}
}
